import { createRouter, createWebHashHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue' // 引入home页面
import ProfileEdit from '@/views/ProfileEdit.vue'

const router = createRouter({
  history: createWebHashHistory(), // 创建路由模式  不带#
  routes: [
    // {
    //   path: '/',
    //   name: 'home',
    //   component: HomeView
    // },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue') // 动态导入 实现路由懒加载的
    // }
    {
      path: '/',
      redirect: '/profile'
    },
    {
      path: '/profile',
      component: ProfileEdit,
      meta: {
        title: '个人资料'
      }
      // 配置规则的同时添加一些额外信息
    },
    {
      path: '/address',
      component: () => import('@/views/AddressManager.vue'),
      meta: {
        title: '地址列表'
      }
    },
    {
      path: '/address/edit/:id',
      component: () => import('@/views/AddressEdit.vue'),
      meta: {
        title: '地址详情'
      }
    }
  ]
})

// router控制了前端页面的展示
// 添加路由后置守卫
router.afterEach((obj) => {
  // 只要路由匹配上了页面  页面展示   就会执行
  console.log('页面匹配了', obj.meta.title)
  //
  document.title = obj.meta.title as string
})

export default router
